:- import "parser.sl" #
:- import "generator.sl" #

Compile .filename :-
	once (
		Parse.File .filename .rules; Error "Parse error"
	)
	!
	forall (list.member .rules .rule) (dump .rule, nl, nl)
	,
	stream.stdout OUT.ASM.FILE,
	set OUTPUT OUT.ASM.FILE
	,
	once (
		Generate .rules;
		Error "Internal generator error"
	)
	,
	Emit.Flush
	,
	stream.close OUT.ASM.FILE,
	unset OUTPUT #

Error .message :-
	get PARSER .parser,
	parser.scanner .parser .scanner,
	scanner.currentLine .scanner .line,
	write "LINE" .line "ERROR:" .message, nl ! #
Error . #
